const { contextBridge, ipcRenderer } = require("electron")
const sendURL = async (url) => {
  let result = await ipcRenderer.invoke('on-url-event', url) // 调用主进程
  return result
}
const alert = (msg) => {
  ipcRenderer.invoke('on-alert-event', msg)
}
const openNewWindow = (url) => {
  ipcRenderer.invoke('on-new-window-event', url)
}
const getFileList = async () => {
  const fileList = await ipcRenderer.invoke('on-get-file-list')
  return fileList
}
const openDialog = () => {
  ipcRenderer.send('on-opendialog-event')
}
const onRendererEvent = (cb) => {
  ipcRenderer.on('on-renderer-event', () => {
    console.log(cb)
    cb()
  })
}
contextBridge.exposeInMainWorld("myApi", {
  sendURL,
  alert,
  openNewWindow,
  getFileList,
  openDialog,
  onRendererEvent
})

